<?php
namespace App\Http\Controllers;

use App\Models\Category;
use App\Models\Click;
use App\Models\Loglogin;
use App\Models\RoleUser;
use App\Models\Startup;
use App\Models\User;
use App\Models\UserCategory;
use App\Models\UserInfo;
use App\Models\Zone;
use Illuminate\Http\Request;
use \Excel;

class ButtonClickController extends CommonController
{

    /**
     * 获取首页发现统计点击频率页面
     */
    public function getIndexDiscover()
    {
        return view('buttonclick.discover');
    }


    /**
     * 获取用户日发现按钮点击率
     */
    public function getDiscoverDayClick()
    {
        $day = 24 * 3600;
        $today_zero = strtotime('today');
        //获取今天差几个小时
        $rest = sprintf("%.2f", (24 - (time() - $today_zero) / 3600));

        $date = array();
        //获取前31天的每天凌晨的时间戳,过去的时间排在前面
        $stamps = array();
        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $today_zero - $i * $day;
            $i > 0 && $date[] = date('m-d', strtotime(-$i . " day"));
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            //获取前三十天的ios登录数据
            $ios = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','tabbarfaxian')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios;
            }

            //获取前三十天的android登录数据
            $android = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','tabbarfaxian')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$android){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$android;
            }

            $total = $ios+$android;
            $t_total = $i_click+$a_click;

            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_total/$total;
            }

            $result = array('total' => $t_frequency,'ios' => $i_frequency, 'android' => $a_frequency);
            $counts[] = $result;
        }


        $today_ios = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','tabbarfaxian')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios;
        }

        $today_android = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','tabbarfaxian')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_android){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_android;
        }

        $today_total = $today_ios+$today_android;
        $today_total_click = $t_i_click+$t_a_click;
        if(0==$today_total){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total;
        }


        $today_result = array('total' => $t_t_frequency, 'ios' => $t_i_frequency, 'android' => $t_a_frequency);
        $counts[] = $today_result;
        $date[] = '今天差' . $rest . '小时';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }
//        dd($arr);

        echo json_encode($arr);
    }


    public function getDiscoverWeekClick()
    {
        //获取本工作周还剩下几天
        $rest = (6 - date('w')) % 7;
        $rest == 0 && $rest = 7;


        //获取上周六凌晨时间戳
        $thisSta = strtotime('today') - (7 - $rest) * 24 * 3600;

        // 定义一周的时间戳
        $week = 7 * 24 * 3600;

        //获取前30周的每周周六凌晨的时间戳,从前往后排
        $stamps = array();
        $date = array();

        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $thisSta - $i * $week;
            $i > 0 && $date[] = '前' . ($i) . '周';
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','tabbarfaxian')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','tabbarfaxian')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $total_click =$a_click+$i_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $total_click/$total;
            }


            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }


        $today_ios_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','tabbarfaxian')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','tabbarfaxian')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $t_total_click = $t_i_click+$t_a_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $t_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本工作周差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }


    public function getDiscoverMonthClick()
    {
        //获取本月还剩下多少天
        $rest = date('t') - date('j') + 1;
        //获取本月1号凌晨的时间戳
        $thisMonth = strtotime(date('Y-m-01'));
        //获取过去十三个月的，每个月1号凌晨的时间戳，从前往后
        $m = date('m');
        $y = date('Y');
        $stamps = array();
        for ($i = 0; $i < 13; $i++) {
            $newM = $m - $i;
            if ($newM <= 0) {
                $newM += 12;
                $y = $y - 1;
            }
            $stamps[] = strtotime($y . '-' . $newM . '-01');
            $y = date('Y');
        }

        $counts = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的登录数据，过去的数据放在前面
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','tabbarfaxian')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','tabbarfaxian')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $t_click = $i_click+$a_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_click/$total;
            }

            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }

        $date = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的文字表述，过去的表述放在前面
            $date[] = $m - $i < 1 ? '去年' . ($m - $i + 12) . '月' : $m - $i . '月';
        }

        $today_ios_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','tabbarfaxian')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','tabbarfaxian')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $today_total_click = $t_a_click+$t_i_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本月差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }

    /**
     * 获取首页发现聊天点击频率页面
     */
    public function getIndexChat()
    {
        return view('buttonclick.chat');
    }

    /**
     * 获取用户日聊天按钮点击率
     */
    public function getChatDayClick()
    {
        $day = 24 * 3600;
        $today_zero = strtotime('today');
        //获取今天差几个小时
        $rest = sprintf("%.2f", (24 - (time() - $today_zero) / 3600));

        $date = array();
        //获取前31天的每天凌晨的时间戳,过去的时间排在前面
        $stamps = array();
        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $today_zero - $i * $day;
            $i > 0 && $date[] = date('m-d', strtotime(-$i . " day"));
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            //获取前三十天的ios登录数据
            $ios = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','tabbarchat')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios;
            }

            //获取前三十天的android登录数据
            $android = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','tabbarchat')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$android){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$android;
            }

            $total = $ios+$android;
            $t_total = $i_click+$a_click;

            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_total/$total;
            }

            $result = array('total' => $t_frequency,'ios' => $i_frequency, 'android' => $a_frequency);
            $counts[] = $result;
        }


        $today_ios = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','tabbarchat')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios;
        }

        $today_android = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','tabbarchat')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_android){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_android;
        }

        $today_total = $today_ios+$today_android;
        $today_total_click = $t_i_click+$t_a_click;
        if(0==$today_total){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total;
        }


        $today_result = array('total' => $t_t_frequency, 'ios' => $t_i_frequency, 'android' => $t_a_frequency);
        $counts[] = $today_result;
        $date[] = '今天差' . $rest . '小时';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }
//        dd($arr);

        echo json_encode($arr);
    }


    public function getChatWeekClick()
    {
        //获取本工作周还剩下几天
        $rest = (6 - date('w')) % 7;
        $rest == 0 && $rest = 7;


        //获取上周六凌晨时间戳
        $thisSta = strtotime('today') - (7 - $rest) * 24 * 3600;

        // 定义一周的时间戳
        $week = 7 * 24 * 3600;

        //获取前30周的每周周六凌晨的时间戳,从前往后排
        $stamps = array();
        $date = array();

        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $thisSta - $i * $week;
            $i > 0 && $date[] = '前' . ($i) . '周';
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','tabbarchat')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','tabbarchat')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $total_click =$a_click+$i_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $total_click/$total;
            }


            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }


        $today_ios_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','tabbarchat')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','tabbarchat')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $t_total_click = $t_i_click+$t_a_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $t_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本工作周差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }


    public function getChatMonthClick()
    {
        //获取本月还剩下多少天
        $rest = date('t') - date('j') + 1;
        //获取本月1号凌晨的时间戳
        $thisMonth = strtotime(date('Y-m-01'));
        //获取过去十三个月的，每个月1号凌晨的时间戳，从前往后
        $m = date('m');
        $y = date('Y');
        $stamps = array();
        for ($i = 0; $i < 13; $i++) {
            $newM = $m - $i;
            if ($newM <= 0) {
                $newM += 12;
                $y = $y - 1;
            }
            $stamps[] = strtotime($y . '-' . $newM . '-01');
            $y = date('Y');
        }

        $counts = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的登录数据，过去的数据放在前面
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','tabbarchat')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','tabbarchat')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $t_click = $i_click+$a_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_click/$total;
            }

            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }

        $date = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的文字表述，过去的表述放在前面
            $date[] = $m - $i < 1 ? '去年' . ($m - $i + 12) . '月' : $m - $i . '月';
        }

        $today_ios_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','tabbarchat')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','tabbarchat')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $today_total_click = $t_a_click+$t_i_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本月差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }

    /**
     * 获取首页发现我的点击频率页面
     */
    public function getIndexMine()
    {
        return view('buttonclick.mine');
    }


    /**
     * 获取用户日我的按钮点击率
     */
    public function getMineDayClick()
    {
        $day = 24 * 3600;
        $today_zero = strtotime('today');
        //获取今天差几个小时
        $rest = sprintf("%.2f", (24 - (time() - $today_zero) / 3600));

        $date = array();
        //获取前31天的每天凌晨的时间戳,过去的时间排在前面
        $stamps = array();
        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $today_zero - $i * $day;
            $i > 0 && $date[] = date('m-d', strtotime(-$i . " day"));
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            //获取前三十天的ios登录数据
            $ios = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','tabbarwode')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios;
            }

            //获取前三十天的android登录数据
            $android = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','tabbarwode')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$android){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$android;
            }

            $total = $ios+$android;
            $t_total = $i_click+$a_click;

            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_total/$total;
            }

            $result = array('total' => $t_frequency,'ios' => $i_frequency, 'android' => $a_frequency);
            $counts[] = $result;
        }


        $today_ios = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','tabbarwode')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios;
        }

        $today_android = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','tabbarwode')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_android){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_android;
        }

        $today_total = $today_ios+$today_android;
        $today_total_click = $t_i_click+$t_a_click;
        if(0==$today_total){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total;
        }


        $today_result = array('total' => $t_t_frequency, 'ios' => $t_i_frequency, 'android' => $t_a_frequency);
        $counts[] = $today_result;
        $date[] = '今天差' . $rest . '小时';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }
//        dd($arr);

        echo json_encode($arr);
    }


    public function getMineWeekClick()
    {
        //获取本工作周还剩下几天
        $rest = (6 - date('w')) % 7;
        $rest == 0 && $rest = 7;


        //获取上周六凌晨时间戳
        $thisSta = strtotime('today') - (7 - $rest) * 24 * 3600;

        // 定义一周的时间戳
        $week = 7 * 24 * 3600;

        //获取前30周的每周周六凌晨的时间戳,从前往后排
        $stamps = array();
        $date = array();

        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $thisSta - $i * $week;
            $i > 0 && $date[] = '前' . ($i) . '周';
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','tabbarwode')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','tabbarwode')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $total_click =$a_click+$i_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $total_click/$total;
            }


            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }


        $today_ios_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','tabbarwode')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','tabbarwode')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $t_total_click = $t_i_click+$t_a_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $t_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本工作周差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }


    public function getMineMonthClick()
    {
        //获取本月还剩下多少天
        $rest = date('t') - date('j') + 1;
        //获取本月1号凌晨的时间戳
        $thisMonth = strtotime(date('Y-m-01'));
        //获取过去十三个月的，每个月1号凌晨的时间戳，从前往后
        $m = date('m');
        $y = date('Y');
        $stamps = array();
        for ($i = 0; $i < 13; $i++) {
            $newM = $m - $i;
            if ($newM <= 0) {
                $newM += 12;
                $y = $y - 1;
            }
            $stamps[] = strtotime($y . '-' . $newM . '-01');
            $y = date('Y');
        }

        $counts = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的登录数据，过去的数据放在前面
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','tabbarwode')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','tabbarwode')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $t_click = $i_click+$a_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_click/$total;
            }

            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }

        $date = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的文字表述，过去的表述放在前面
            $date[] = $m - $i < 1 ? '去年' . ($m - $i + 12) . '月' : $m - $i . '月';
        }

        $today_ios_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','tabbarwode')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','tabbarwode')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $today_total_click = $t_a_click+$t_i_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本月差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }



    /**
     * 获取首页发现项目点击频率页面
     */
    public function getDiscoverProject()
    {
        return view('buttonclick.discoverproject');
    }

    /**
     * 获取用户日发现项目的按钮点击率
     */
    public function getDpDayClick()
    {
        $day = 24 * 3600;
        $today_zero = strtotime('today');
        //获取今天差几个小时
        $rest = sprintf("%.2f", (24 - (time() - $today_zero) / 3600));

        $date = array();
        //获取前31天的每天凌晨的时间戳,过去的时间排在前面
        $stamps = array();
        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $today_zero - $i * $day;
            $i > 0 && $date[] = date('m-d', strtotime(-$i . " day"));
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            //获取前三十天的ios登录数据
            $ios = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxianxiangmu')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios;
            }

            //获取前三十天的android登录数据
            $android = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxianxiangmu')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$android){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$android;
            }

            $total = $ios+$android;
            $t_total = $i_click+$a_click;

            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_total/$total;
            }

            $result = array('total' => $t_frequency,'ios' => $i_frequency, 'android' => $a_frequency);
            $counts[] = $result;
        }


        $today_ios = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','faxianxiangmu')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios;
        }

        $today_android = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','faxianxiangmu')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_android){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_android;
        }

        $today_total = $today_ios+$today_android;
        $today_total_click = $t_i_click+$t_a_click;
        if(0==$today_total){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total;
        }


        $today_result = array('total' => $t_t_frequency, 'ios' => $t_i_frequency, 'android' => $t_a_frequency);
        $counts[] = $today_result;
        $date[] = '今天差' . $rest . '小时';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }
//        dd($arr);

        echo json_encode($arr);
    }


    public function getDpWeekClick()
    {
        //获取本工作周还剩下几天
        $rest = (6 - date('w')) % 7;
        $rest == 0 && $rest = 7;


        //获取上周六凌晨时间戳
        $thisSta = strtotime('today') - (7 - $rest) * 24 * 3600;

        // 定义一周的时间戳
        $week = 7 * 24 * 3600;

        //获取前30周的每周周六凌晨的时间戳,从前往后排
        $stamps = array();
        $date = array();

        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $thisSta - $i * $week;
            $i > 0 && $date[] = '前' . ($i) . '周';
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxianxiangmu')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxianxiangmu')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $total_click =$a_click+$i_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $total_click/$total;
            }


            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }


        $today_ios_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','faxianxiangmu')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','faxianxiangmu')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $t_total_click = $t_i_click+$t_a_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $t_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本工作周差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }


    public function getDpMonthClick()
    {
        //获取本月还剩下多少天
        $rest = date('t') - date('j') + 1;
        //获取本月1号凌晨的时间戳
        $thisMonth = strtotime(date('Y-m-01'));
        //获取过去十三个月的，每个月1号凌晨的时间戳，从前往后
        $m = date('m');
        $y = date('Y');
        $stamps = array();
        for ($i = 0; $i < 13; $i++) {
            $newM = $m - $i;
            if ($newM <= 0) {
                $newM += 12;
                $y = $y - 1;
            }
            $stamps[] = strtotime($y . '-' . $newM . '-01');
            $y = date('Y');
        }

        $counts = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的登录数据，过去的数据放在前面
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','faxianxiangmu')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','faxianxiangmu')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $t_click = $i_click+$a_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_click/$total;
            }

            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }

        $date = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的文字表述，过去的表述放在前面
            $date[] = $m - $i < 1 ? '去年' . ($m - $i + 12) . '月' : $m - $i . '月';
        }

        $today_ios_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','faxianxiangmu')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','faxianxiangmu')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $today_total_click = $t_a_click+$t_i_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本月差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }


    /**
     * 获取首页发现投资人点击频率页面
     */
    public function getDiscoverInvest()
    {
        return view('buttonclick.discoverinvest');
    }

    /**
     * 获取用户日发现项目的按钮点击率
     */
    public function getDiDayClick()
    {
        $day = 24 * 3600;
        $today_zero = strtotime('today');
        //获取今天差几个小时
        $rest = sprintf("%.2f", (24 - (time() - $today_zero) / 3600));

        $date = array();
        //获取前31天的每天凌晨的时间戳,过去的时间排在前面
        $stamps = array();
        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $today_zero - $i * $day;
            $i > 0 && $date[] = date('m-d', strtotime(-$i . " day"));
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            //获取前三十天的ios登录数据
            $ios = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxiantouziren')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios;
            }

            //获取前三十天的android登录数据
            $android = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxiantouziren')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$android){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$android;
            }

            $total = $ios+$android;
            $t_total = $i_click+$a_click;

            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_total/$total;
            }

            $result = array('total' => $t_frequency,'ios' => $i_frequency, 'android' => $a_frequency);
            $counts[] = $result;
        }


        $today_ios = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','faxiantouziren')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios;
        }

        $today_android = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','faxiantouziren')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_android){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_android;
        }

        $today_total = $today_ios+$today_android;
        $today_total_click = $t_i_click+$t_a_click;
        if(0==$today_total){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total;
        }


        $today_result = array('total' => $t_t_frequency, 'ios' => $t_i_frequency, 'android' => $t_a_frequency);
        $counts[] = $today_result;
        $date[] = '今天差' . $rest . '小时';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }
//        dd($arr);

        echo json_encode($arr);
    }


    public function getDiWeekClick()
    {
        //获取本工作周还剩下几天
        $rest = (6 - date('w')) % 7;
        $rest == 0 && $rest = 7;


        //获取上周六凌晨时间戳
        $thisSta = strtotime('today') - (7 - $rest) * 24 * 3600;

        // 定义一周的时间戳
        $week = 7 * 24 * 3600;

        //获取前30周的每周周六凌晨的时间戳,从前往后排
        $stamps = array();
        $date = array();

        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $thisSta - $i * $week;
            $i > 0 && $date[] = '前' . ($i) . '周';
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxiantouziren')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxiantouziren')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $total_click =$a_click+$i_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $total_click/$total;
            }


            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }


        $today_ios_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','faxiantouziren')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','faxiantouziren')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $t_total_click = $t_i_click+$t_a_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $t_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本工作周差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }


    public function getDiMonthClick()
    {
        //获取本月还剩下多少天
        $rest = date('t') - date('j') + 1;
        //获取本月1号凌晨的时间戳
        $thisMonth = strtotime(date('Y-m-01'));
        //获取过去十三个月的，每个月1号凌晨的时间戳，从前往后
        $m = date('m');
        $y = date('Y');
        $stamps = array();
        for ($i = 0; $i < 13; $i++) {
            $newM = $m - $i;
            if ($newM <= 0) {
                $newM += 12;
                $y = $y - 1;
            }
            $stamps[] = strtotime($y . '-' . $newM . '-01');
            $y = date('Y');
        }

        $counts = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的登录数据，过去的数据放在前面
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','faxiantouziren')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','faxiantouziren')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $t_click = $i_click+$a_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_click/$total;
            }

            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }

        $date = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的文字表述，过去的表述放在前面
            $date[] = $m - $i < 1 ? '去年' . ($m - $i + 12) . '月' : $m - $i . '月';
        }

        $today_ios_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','faxiantouziren')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','faxiantouziren')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $today_total_click = $t_a_click+$t_i_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本月差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }

    /**
     * 获取首页发现创客空间点击频率页面
     */
    public function getDiscoverMaker()
    {
        return view('buttonclick.discovermaker');
    }

    /**
     * 获取用户日发现创客空间的按钮点击率
     */
    public function getDmDayClick()
    {
        $day = 24 * 3600;
        $today_zero = strtotime('today');
        //获取今天差几个小时
        $rest = sprintf("%.2f", (24 - (time() - $today_zero) / 3600));

        $date = array();
        //获取前31天的每天凌晨的时间戳,过去的时间排在前面
        $stamps = array();
        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $today_zero - $i * $day;
            $i > 0 && $date[] = date('m-d', strtotime(-$i . " day"));
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            //获取前三十天的ios登录数据
            $ios = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxianchuangkekongjian')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios;
            }

            //获取前三十天的android登录数据
            $android = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxianchuangkekongjian')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$android){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$android;
            }

            $total = $ios+$android;
            $t_total = $i_click+$a_click;

            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_total/$total;
            }

            $result = array('total' => $t_frequency,'ios' => $i_frequency, 'android' => $a_frequency);
            $counts[] = $result;
        }


        $today_ios = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','faxianchuangkekongjian')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios;
        }

        $today_android = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','faxianchuangkekongjian')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_android){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_android;
        }

        $today_total = $today_ios+$today_android;
        $today_total_click = $t_i_click+$t_a_click;
        if(0==$today_total){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total;
        }


        $today_result = array('total' => $t_t_frequency, 'ios' => $t_i_frequency, 'android' => $t_a_frequency);
        $counts[] = $today_result;
        $date[] = '今天差' . $rest . '小时';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }
//        dd($arr);

        echo json_encode($arr);
    }


    public function getDmWeekClick()
    {
        //获取本工作周还剩下几天
        $rest = (6 - date('w')) % 7;
        $rest == 0 && $rest = 7;


        //获取上周六凌晨时间戳
        $thisSta = strtotime('today') - (7 - $rest) * 24 * 3600;

        // 定义一周的时间戳
        $week = 7 * 24 * 3600;

        //获取前30周的每周周六凌晨的时间戳,从前往后排
        $stamps = array();
        $date = array();

        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $thisSta - $i * $week;
            $i > 0 && $date[] = '前' . ($i) . '周';
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxianchuangkekongjian')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxianchuangkekongjian')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $total_click =$a_click+$i_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $total_click/$total;
            }


            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }


        $today_ios_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','faxianchuangkekongjian')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','faxianchuangkekongjian')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $t_total_click = $t_i_click+$t_a_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $t_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本工作周差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }


    public function getDmMonthClick()
    {
        //获取本月还剩下多少天
        $rest = date('t') - date('j') + 1;
        //获取本月1号凌晨的时间戳
        $thisMonth = strtotime(date('Y-m-01'));
        //获取过去十三个月的，每个月1号凌晨的时间戳，从前往后
        $m = date('m');
        $y = date('Y');
        $stamps = array();
        for ($i = 0; $i < 13; $i++) {
            $newM = $m - $i;
            if ($newM <= 0) {
                $newM += 12;
                $y = $y - 1;
            }
            $stamps[] = strtotime($y . '-' . $newM . '-01');
            $y = date('Y');
        }

        $counts = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的登录数据，过去的数据放在前面
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','faxianchuangkekongjian')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','faxianchuangkekongjian')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $t_click = $i_click+$a_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_click/$total;
            }

            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }

        $date = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的文字表述，过去的表述放在前面
            $date[] = $m - $i < 1 ? '去年' . ($m - $i + 12) . '月' : $m - $i . '月';
        }

        $today_ios_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','faxianchuangkekongjian')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','faxianchuangkekongjian')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $today_total_click = $t_a_click+$t_i_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本月差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }

    /**
     * 获取首页发现热门群聊点击频率页面
     */
    public function getDiscoverChat()
    {
        return view('buttonclick.discoverchat');
    }


    /**
     * 获取用户日发现创客空间的按钮点击率
     */
    public function getDcDayClick()
    {
        $day = 24 * 3600;
        $today_zero = strtotime('today');
        //获取今天差几个小时
        $rest = sprintf("%.2f", (24 - (time() - $today_zero) / 3600));

        $date = array();
        //获取前31天的每天凌晨的时间戳,过去的时间排在前面
        $stamps = array();
        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $today_zero - $i * $day;
            $i > 0 && $date[] = date('m-d', strtotime(-$i . " day"));
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            //获取前三十天的ios登录数据
            $ios = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxianqunliao')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios;
            }

            //获取前三十天的android登录数据
            $android = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxianqunliao')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$android){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$android;
            }

            $total = $ios+$android;
            $t_total = $i_click+$a_click;

            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_total/$total;
            }

            $result = array('total' => $t_frequency,'ios' => $i_frequency, 'android' => $a_frequency);
            $counts[] = $result;
        }


        $today_ios = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','faxianqunliao')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios;
        }

        $today_android = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','faxianqunliao')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_android){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_android;
        }

        $today_total = $today_ios+$today_android;
        $today_total_click = $t_i_click+$t_a_click;
        if(0==$today_total){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total;
        }


        $today_result = array('total' => $t_t_frequency, 'ios' => $t_i_frequency, 'android' => $t_a_frequency);
        $counts[] = $today_result;
        $date[] = '今天差' . $rest . '小时';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }
//        dd($arr);

        echo json_encode($arr);
    }


    public function getDcWeekClick()
    {
        //获取本工作周还剩下几天
        $rest = (6 - date('w')) % 7;
        $rest == 0 && $rest = 7;


        //获取上周六凌晨时间戳
        $thisSta = strtotime('today') - (7 - $rest) * 24 * 3600;

        // 定义一周的时间戳
        $week = 7 * 24 * 3600;

        //获取前30周的每周周六凌晨的时间戳,从前往后排
        $stamps = array();
        $date = array();

        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $thisSta - $i * $week;
            $i > 0 && $date[] = '前' . ($i) . '周';
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxianqunliao')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','faxianqunliao')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $total_click =$a_click+$i_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $total_click/$total;
            }


            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }


        $today_ios_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','faxianqunliao')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','faxianqunliao')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $t_total_click = $t_i_click+$t_a_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $t_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本工作周差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }


    public function getDcMonthClick()
    {
        //获取本月还剩下多少天
        $rest = date('t') - date('j') + 1;
        //获取本月1号凌晨的时间戳
        $thisMonth = strtotime(date('Y-m-01'));
        //获取过去十三个月的，每个月1号凌晨的时间戳，从前往后
        $m = date('m');
        $y = date('Y');
        $stamps = array();
        for ($i = 0; $i < 13; $i++) {
            $newM = $m - $i;
            if ($newM <= 0) {
                $newM += 12;
                $y = $y - 1;
            }
            $stamps[] = strtotime($y . '-' . $newM . '-01');
            $y = date('Y');
        }

        $counts = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的登录数据，过去的数据放在前面
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','faxianqunliao')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','faxianqunliao')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $t_click = $i_click+$a_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_click/$total;
            }

            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }

        $date = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的文字表述，过去的表述放在前面
            $date[] = $m - $i < 1 ? '去年' . ($m - $i + 12) . '月' : $m - $i . '月';
        }

        $today_ios_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','faxianqunliao')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','faxianqunliao')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $today_total_click = $t_a_click+$t_i_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本月差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }


    /**
     * 获取首页我要路演点击频率页面
     */
    public function getIndexShow()
    {
        return view('buttonclick.indexshow');
    }


    /**
     * 获取用户日首页我要路演的按钮点击率
     */
    public function getIsDayClick()
    {
        $day = 24 * 3600;
        $today_zero = strtotime('today');
        //获取今天差几个小时
        $rest = sprintf("%.2f", (24 - (time() - $today_zero) / 3600));

        $date = array();
        //获取前31天的每天凌晨的时间戳,过去的时间排在前面
        $stamps = array();
        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $today_zero - $i * $day;
            $i > 0 && $date[] = date('m-d', strtotime(-$i . " day"));
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            //获取前三十天的ios登录数据
            $ios = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexroadshow')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios;
            }

            //获取前三十天的android登录数据
            $android = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexroadshow')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$android){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$android;
            }

            $total = $ios+$android;
            $t_total = $i_click+$a_click;

            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_total/$total;
            }

            $result = array('total' => $t_frequency,'ios' => $i_frequency, 'android' => $a_frequency);
            $counts[] = $result;
        }


        $today_ios = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','indexroadshow')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios;
        }

        $today_android = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','indexroadshow')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_android){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_android;
        }

        $today_total = $today_ios+$today_android;
        $today_total_click = $t_i_click+$t_a_click;
        if(0==$today_total){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total;
        }


        $today_result = array('total' => $t_t_frequency, 'ios' => $t_i_frequency, 'android' => $t_a_frequency);
        $counts[] = $today_result;
        $date[] = '今天差' . $rest . '小时';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }
//        dd($arr);

        echo json_encode($arr);
    }


    public function getIsWeekClick()
    {
        //获取本工作周还剩下几天
        $rest = (6 - date('w')) % 7;
        $rest == 0 && $rest = 7;


        //获取上周六凌晨时间戳
        $thisSta = strtotime('today') - (7 - $rest) * 24 * 3600;

        // 定义一周的时间戳
        $week = 7 * 24 * 3600;

        //获取前30周的每周周六凌晨的时间戳,从前往后排
        $stamps = array();
        $date = array();

        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $thisSta - $i * $week;
            $i > 0 && $date[] = '前' . ($i) . '周';
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexroadshow')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexroadshow')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $total_click =$a_click+$i_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $total_click/$total;
            }


            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }


        $today_ios_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','indexroadshow')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','indexroadshow')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $t_total_click = $t_i_click+$t_a_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $t_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本工作周差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }


    public function getIsMonthClick()
    {
        //获取本月还剩下多少天
        $rest = date('t') - date('j') + 1;
        //获取本月1号凌晨的时间戳
        $thisMonth = strtotime(date('Y-m-01'));
        //获取过去十三个月的，每个月1号凌晨的时间戳，从前往后
        $m = date('m');
        $y = date('Y');
        $stamps = array();
        for ($i = 0; $i < 13; $i++) {
            $newM = $m - $i;
            if ($newM <= 0) {
                $newM += 12;
                $y = $y - 1;
            }
            $stamps[] = strtotime($y . '-' . $newM . '-01');
            $y = date('Y');
        }

        $counts = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的登录数据，过去的数据放在前面
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','indexroadshow')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','indexroadshow')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $t_click = $i_click+$a_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_click/$total;
            }

            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }

        $date = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的文字表述，过去的表述放在前面
            $date[] = $m - $i < 1 ? '去年' . ($m - $i + 12) . '月' : $m - $i . '月';
        }

        $today_ios_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','indexroadshow')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','indexroadshow')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $today_total_click = $t_a_click+$t_i_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本月差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }



    /**
     * 获取首页最新活动点击频率页面
     */
    public function getIndexNew()
    {
        return view('buttonclick.indexnew');
    }


    /**
     * 获取用户日首页最新活动的按钮点击率
     */
    public function getInDayClick()
    {
        $day = 24 * 3600;
        $today_zero = strtotime('today');
        //获取今天差几个小时
        $rest = sprintf("%.2f", (24 - (time() - $today_zero) / 3600));

        $date = array();
        //获取前31天的每天凌晨的时间戳,过去的时间排在前面
        $stamps = array();
        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $today_zero - $i * $day;
            $i > 0 && $date[] = date('m-d', strtotime(-$i . " day"));
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            //获取前三十天的ios登录数据
            $ios = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexnewactivity')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios;
            }

            //获取前三十天的android登录数据
            $android = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexnewactivity')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$android){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$android;
            }

            $total = $ios+$android;
            $t_total = $i_click+$a_click;

            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_total/$total;
            }

            $result = array('total' => $t_frequency,'ios' => $i_frequency, 'android' => $a_frequency);
            $counts[] = $result;
        }


        $today_ios = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','indexnewactivity')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios;
        }

        $today_android = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','indexnewactivity')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_android){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_android;
        }

        $today_total = $today_ios+$today_android;
        $today_total_click = $t_i_click+$t_a_click;
        if(0==$today_total){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total;
        }


        $today_result = array('total' => $t_t_frequency, 'ios' => $t_i_frequency, 'android' => $t_a_frequency);
        $counts[] = $today_result;
        $date[] = '今天差' . $rest . '小时';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }
//        dd($arr);

        echo json_encode($arr);
    }


    public function getInWeekClick()
    {
        //获取本工作周还剩下几天
        $rest = (6 - date('w')) % 7;
        $rest == 0 && $rest = 7;


        //获取上周六凌晨时间戳
        $thisSta = strtotime('today') - (7 - $rest) * 24 * 3600;

        // 定义一周的时间戳
        $week = 7 * 24 * 3600;

        //获取前30周的每周周六凌晨的时间戳,从前往后排
        $stamps = array();
        $date = array();

        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $thisSta - $i * $week;
            $i > 0 && $date[] = '前' . ($i) . '周';
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexnewactivity')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexnewactivity')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $total_click =$a_click+$i_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $total_click/$total;
            }


            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }


        $today_ios_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','indexnewactivity')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','indexnewactivity')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $t_total_click = $t_i_click+$t_a_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $t_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本工作周差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }


    public function getInMonthClick()
    {
        //获取本月还剩下多少天
        $rest = date('t') - date('j') + 1;
        //获取本月1号凌晨的时间戳
        $thisMonth = strtotime(date('Y-m-01'));
        //获取过去十三个月的，每个月1号凌晨的时间戳，从前往后
        $m = date('m');
        $y = date('Y');
        $stamps = array();
        for ($i = 0; $i < 13; $i++) {
            $newM = $m - $i;
            if ($newM <= 0) {
                $newM += 12;
                $y = $y - 1;
            }
            $stamps[] = strtotime($y . '-' . $newM . '-01');
            $y = date('Y');
        }

        $counts = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的登录数据，过去的数据放在前面
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','indexnewactivity')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','indexnewactivity')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $t_click = $i_click+$a_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_click/$total;
            }

            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }

        $date = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的文字表述，过去的表述放在前面
            $date[] = $m - $i < 1 ? '去年' . ($m - $i + 12) . '月' : $m - $i . '月';
        }

        $today_ios_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','indexnewactivity')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','indexnewactivity')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $today_total_click = $t_a_click+$t_i_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本月差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }




    /**
     * 获取首页活动发布点击频率页面
     */
    public function getIndexPost()
    {
        return view('buttonclick.indexpost');
    }


    /**
     * 获取用户日首页最新活动的按钮点击率
     */
    public function getIpDayClick()
    {
        $day = 24 * 3600;
        $today_zero = strtotime('today');
        //获取今天差几个小时
        $rest = sprintf("%.2f", (24 - (time() - $today_zero) / 3600));

        $date = array();
        //获取前31天的每天凌晨的时间戳,过去的时间排在前面
        $stamps = array();
        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $today_zero - $i * $day;
            $i > 0 && $date[] = date('m-d', strtotime(-$i . " day"));
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            //获取前三十天的ios登录数据
            $ios = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexactivitypost')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios;
            }

            //获取前三十天的android登录数据
            $android = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexactivitypost')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$android){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$android;
            }

            $total = $ios+$android;
            $t_total = $i_click+$a_click;

            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_total/$total;
            }

            $result = array('total' => $t_frequency,'ios' => $i_frequency, 'android' => $a_frequency);
            $counts[] = $result;
        }


        $today_ios = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','indexactivitypost')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios;
        }

        $today_android = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','indexactivitypost')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_android){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_android;
        }

        $today_total = $today_ios+$today_android;
        $today_total_click = $t_i_click+$t_a_click;
        if(0==$today_total){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total;
        }


        $today_result = array('total' => $t_t_frequency, 'ios' => $t_i_frequency, 'android' => $t_a_frequency);
        $counts[] = $today_result;
        $date[] = '今天差' . $rest . '小时';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }
//        dd($arr);

        echo json_encode($arr);
    }


    public function getIpWeekClick()
    {
        //获取本工作周还剩下几天
        $rest = (6 - date('w')) % 7;
        $rest == 0 && $rest = 7;


        //获取上周六凌晨时间戳
        $thisSta = strtotime('today') - (7 - $rest) * 24 * 3600;

        // 定义一周的时间戳
        $week = 7 * 24 * 3600;

        //获取前30周的每周周六凌晨的时间戳,从前往后排
        $stamps = array();
        $date = array();

        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $thisSta - $i * $week;
            $i > 0 && $date[] = '前' . ($i) . '周';
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexactivitypost')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexactivitypost')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $total_click =$a_click+$i_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $total_click/$total;
            }


            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }


        $today_ios_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','indexactivitypost')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','indexactivitypost')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $t_total_click = $t_i_click+$t_a_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $t_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本工作周差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }


    public function getIpMonthClick()
    {
        //获取本月还剩下多少天
        $rest = date('t') - date('j') + 1;
        //获取本月1号凌晨的时间戳
        $thisMonth = strtotime(date('Y-m-01'));
        //获取过去十三个月的，每个月1号凌晨的时间戳，从前往后
        $m = date('m');
        $y = date('Y');
        $stamps = array();
        for ($i = 0; $i < 13; $i++) {
            $newM = $m - $i;
            if ($newM <= 0) {
                $newM += 12;
                $y = $y - 1;
            }
            $stamps[] = strtotime($y . '-' . $newM . '-01');
            $y = date('Y');
        }

        $counts = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的登录数据，过去的数据放在前面
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','indexactivitypost')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','indexactivitypost')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $t_click = $i_click+$a_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_click/$total;
            }

            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }

        $date = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的文字表述，过去的表述放在前面
            $date[] = $m - $i < 1 ? '去年' . ($m - $i + 12) . '月' : $m - $i . '月';
        }

        $today_ios_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','indexactivitypost')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','indexactivitypost')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $today_total_click = $t_a_click+$t_i_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本月差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }

    /**
     * 获取首页资方直通点击频率页面
     */
    public function getIndexContact()
    {
        return view('buttonclick.indexcontact');
    }


    /**
     * 获取用户日首页最新活动的按钮点击率
     */
    public function getIcDayClick()
    {
        $day = 24 * 3600;
        $today_zero = strtotime('today');
        //获取今天差几个小时
        $rest = sprintf("%.2f", (24 - (time() - $today_zero) / 3600));

        $date = array();
        //获取前31天的每天凌晨的时间戳,过去的时间排在前面
        $stamps = array();
        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $today_zero - $i * $day;
            $i > 0 && $date[] = date('m-d', strtotime(-$i . " day"));
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            //获取前三十天的ios登录数据
            $ios = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexinvestcontact')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios;
            }

            //获取前三十天的android登录数据
            $android = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client',7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexinvestcontact')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$android){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$android;
            }

            $total = $ios+$android;
            $t_total = $i_click+$a_click;

            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_total/$total;
            }

            $result = array('total' => $t_frequency,'ios' => $i_frequency, 'android' => $a_frequency);
            $counts[] = $result;
        }


        $today_ios = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','indexinvestcontact')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios;
        }

        $today_android = Startup::whereBetween('created_at', [$today_zero, time()])->where('client',7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$today_zero, time()])->where('clickTarget','indexinvestcontact')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_android){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_android;
        }

        $today_total = $today_ios+$today_android;
        $today_total_click = $t_i_click+$t_a_click;
        if(0==$today_total){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total;
        }


        $today_result = array('total' => $t_t_frequency, 'ios' => $t_i_frequency, 'android' => $t_a_frequency);
        $counts[] = $today_result;
        $date[] = '今天差' . $rest . '小时';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }
//        dd($arr);

        echo json_encode($arr);
    }


    public function getIcWeekClick()
    {
        //获取本工作周还剩下几天
        $rest = (6 - date('w')) % 7;
        $rest == 0 && $rest = 7;


        //获取上周六凌晨时间戳
        $thisSta = strtotime('today') - (7 - $rest) * 24 * 3600;

        // 定义一周的时间戳
        $week = 7 * 24 * 3600;

        //获取前30周的每周周六凌晨的时间戳,从前往后排
        $stamps = array();
        $date = array();

        for ($i = 30; $i >= 0; $i--) {
            $stamps[] = $thisSta - $i * $week;
            $i > 0 && $date[] = '前' . ($i) . '周';
        }

        $counts = array();
        for ($i = 1; $i < 31; $i++) {
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexinvestcontact')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i - 1], $stamps[$i]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i - 1], $stamps[$i]])->where('clickTarget','indexinvestcontact')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $total_click =$a_click+$i_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $total_click/$total;
            }


            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }


        $today_ios_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','indexinvestcontact')->where('headers', 'like', '%' . 'ios' . '%')->count();
        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisSta, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisSta, time()])->where('clickTarget','indexinvestcontact')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $t_total_click = $t_i_click+$t_a_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $t_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本工作周差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }


    public function getIcMonthClick()
    {
        //获取本月还剩下多少天
        $rest = date('t') - date('j') + 1;
        //获取本月1号凌晨的时间戳
        $thisMonth = strtotime(date('Y-m-01'));
        //获取过去十三个月的，每个月1号凌晨的时间戳，从前往后
        $m = date('m');
        $y = date('Y');
        $stamps = array();
        for ($i = 0; $i < 13; $i++) {
            $newM = $m - $i;
            if ($newM <= 0) {
                $newM += 12;
                $y = $y - 1;
            }
            $stamps[] = strtotime($y . '-' . $newM . '-01');
            $y = date('Y');
        }

        $counts = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的登录数据，过去的数据放在前面
            $ios_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 8)->count();
            $i_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','indexinvestcontact')->where('headers', 'like', '%' . 'ios' . '%')->count();
            if(0==$ios_count){
                $i_frequency = 0;
            }else{
                $i_frequency = $i_click/$ios_count;
            }

            $ad_count = Startup::whereBetween('created_at', [$stamps[$i], $stamps[$i-1]])->where('client', 7)->count();
            $a_click = Click::whereBetween('insert_time', [$stamps[$i], $stamps[$i-1]])->where('clickTarget','indexinvestcontact')->where('headers', 'like', '%' . 'android' . '%')->count();
            if(0==$ad_count){
                $a_frequency = 0;
            }else{
                $a_frequency = $a_click/$ad_count;
            }

            $total = $ios_count+$ad_count;
            $t_click = $i_click+$a_click;
            if(0==$total){
                $t_frequency = 0;
            }else{
                $t_frequency = $t_click/$total;
            }

            $result = array('total' => $t_frequency, 'ios' => $i_frequency, 'android' => $a_frequency);

            $counts[] = $result;
        }

        $date = array();
        for ($i = 12; $i > 0; $i--) {
            //获取前12个月的文字表述，过去的表述放在前面
            $date[] = $m - $i < 1 ? '去年' . ($m - $i + 12) . '月' : $m - $i . '月';
        }

        $today_ios_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 8)->count();
        $t_i_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','indexinvestcontact')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ios_count){
            $t_i_frequency = 0;
        }else{
            $t_i_frequency = $t_i_click/$today_ios_count;
        }

        $today_ad_count = Startup::whereBetween('created_at', [$thisMonth, time()])->where('client', 7)->count();
        $t_a_click = Click::whereBetween('insert_time', [$thisMonth, time()])->where('clickTarget','indexinvestcontact')->where('headers', 'like', '%' . 'android' . '%')->count();

        if(0==$today_ad_count){
            $t_a_frequency = 0;
        }else{
            $t_a_frequency = $t_a_click/$today_ad_count;
        }

        $today_total_count = $today_ios_count+$today_ad_count;
        $today_total_click = $t_a_click+$t_i_click;
        if(0==$today_total_count){
            $t_t_frequency = 0;
        }else{
            $t_t_frequency = $today_total_click/$today_total_count;
        }

        $today_result = array('total' => $t_t_frequency,'ios' => $t_i_frequency, 'android' => $t_a_frequency);

        $counts[]= $today_result;
        $date[] = '本月差' . $rest . '天';

        $arr = [];
        foreach ($date as $k => $i) {
            $arr[] = array($i, $counts[$k]);
        }

        echo json_encode($arr);
    }

}